***preamble

clear
clear matrix
clear mata
set maxvar 30000

***load data

use "${path}\data\acs\acs.dta" , clear

***prepare outcomes

gen lifesciences = .
replace lifesciences=0 if occ2010>0 & occ2010!=.
replace lifesciences=100 if occ2010>=1600 & occ2010<=1650
label variable lifesciences "Life Sciences"

gen aggriscientistocc = .
replace aggriscientistocc=0 if occ2010>0 & occ2010!=.
replace aggriscientistocc=100 if occ2010==1600
label variable aggriscientistocc "Agriculture and Food"

gen biologyscientistocc = .
replace biologyscientistocc=0 if occ2010>0 & occ2010!=.
replace biologyscientistocc=100 if occ2010==1610
label variable biologyscientistocc "Biology"

gen conservationscientistocc = .
replace conservationscientistocc=0 if occ2010>0 & occ2010!=.
replace conservationscientistocc=100 if occ2010==1640
label variable conservationscientistocc "Conservation and Forestry"

gen medscientistocc = .
replace medscientistocc=0 if occ2010>0 & occ2010!=.
replace medscientistocc=100 if occ2010==1650
label variable medscientistocc "Medical and Other"

***cut dataset and prepare for treatment definition

gen highschoolentryyear=birthyr+14
drop if bpl>56
keep if highschoolentryyear>1990
keep if highschoolentryyear<2010
drop if age<19

***prepare treatments

gen evolution_score=.
replace evolution_score=9 if bpl==1 & highschoolentryyear<2005
replace evolution_score=21 if bpl==1 & highschoolentryyear>=2005
replace evolution_score=48 if bpl==2 & highschoolentryyear<2006
replace evolution_score=59 if bpl==2 & highschoolentryyear>=2006
replace evolution_score=82 if bpl==4 & highschoolentryyear<2005
replace evolution_score=82 if bpl==4 & highschoolentryyear>=2005
replace evolution_score=55 if bpl==5 & highschoolentryyear<2005
replace evolution_score=66 if bpl==5 & highschoolentryyear>=2005
replace evolution_score=100 if bpl==6
replace evolution_score=86 if bpl==8 & highschoolentryyear<2009
replace evolution_score=82 if bpl==8 & highschoolentryyear>=2009
replace evolution_score=100 if bpl==9 & highschoolentryyear<2004
replace evolution_score=59 if bpl==9 & highschoolentryyear>=2004
replace evolution_score=91 if bpl==10 & highschoolentryyear<2006
replace evolution_score=80 if bpl==10 & highschoolentryyear>=2006
replace evolution_score=80 if bpl==11 & highschoolentryyear<2006
replace evolution_score=96 if bpl==11 & highschoolentryyear>=2006
replace evolution_score=16 if bpl==12 & highschoolentryyear<2008
replace evolution_score=91 if bpl==12 & highschoolentryyear>=2008
replace evolution_score=7 if bpl==13 & highschoolentryyear<2004
replace evolution_score=66 if bpl==13 & highschoolentryyear>=2004
replace evolution_score=91 if bpl==15 & highschoolentryyear<2005
replace evolution_score=75 if bpl==15 & highschoolentryyear>=2005
replace evolution_score=82 if bpl==16 & highschoolentryyear<2007
replace evolution_score=82 if bpl==16 & highschoolentryyear>=2007
replace evolution_score=45 if bpl==17 & highschoolentryyear<2004
replace evolution_score=82 if bpl==17 & highschoolentryyear>=2004
replace evolution_score=100 if bpl==18 & highschoolentryyear<2006
replace evolution_score=96 if bpl==18 & highschoolentryyear>=2006
replace evolution_score=77 if bpl==19 & highschoolentryyear>=2007
replace evolution_score=0 if bpl==20 & highschoolentryyear<2007
replace evolution_score=96 if bpl==20 & highschoolentryyear>=2007
replace evolution_score=55 if bpl==21 & highschoolentryyear<2006
replace evolution_score=55 if bpl==21 & highschoolentryyear>=2006
replace evolution_score=64 if bpl==22 & highschoolentryyear<2005
replace evolution_score=27 if bpl==22 & highschoolentryyear>=2005
replace evolution_score=30 if bpl==23 & highschoolentryyear<2007
replace evolution_score=68 if bpl==23 & highschoolentryyear>=2007
replace evolution_score=77 if bpl==24 & highschoolentryyear<2002
replace evolution_score=73 if bpl==24 & highschoolentryyear>=2002
replace evolution_score=82 if bpl==25 & highschoolentryyear<2006
replace evolution_score=84 if bpl==25 & highschoolentryyear>=2006
replace evolution_score=84 if bpl==26 & highschoolentryyear<2000
replace evolution_score=80 if bpl==26 & highschoolentryyear>=2000
replace evolution_score=86 if bpl==27 & highschoolentryyear<2009
replace evolution_score=89 if bpl==27 & highschoolentryyear>=2009
replace evolution_score=5 if bpl==28 & highschoolentryyear<2008
replace evolution_score=87 if bpl==28 & highschoolentryyear>=2008
replace evolution_score=82 if bpl==29 & highschoolentryyear<2008
replace evolution_score=78 if bpl==29 & highschoolentryyear>=2008
replace evolution_score=82 if bpl==30 & highschoolentryyear<2006
replace evolution_score=75 if bpl==30 & highschoolentryyear>=2006
replace evolution_score=66 if bpl==31 
replace evolution_score=70 if bpl==32 & highschoolentryyear<2004
replace evolution_score=77 if bpl==32 & highschoolentryyear>=2004
replace evolution_score=23 if bpl==33 & highschoolentryyear<2006
replace evolution_score=91 if bpl==33 & highschoolentryyear>=2006
replace evolution_score=100 if bpl==34 & highschoolentryyear<2002
replace evolution_score=100 if bpl==34 & highschoolentryyear>=2002
replace evolution_score=73 if bpl==35 & highschoolentryyear<2003
replace evolution_score=91 if bpl==35 & highschoolentryyear>=2003
replace evolution_score=68 if bpl==36
replace evolution_score=100 if bpl==37 & highschoolentryyear<2004
replace evolution_score=82 if bpl==37 & highschoolentryyear>=2004
replace evolution_score=9 if bpl==38 & highschoolentryyear<2006
replace evolution_score=64 if bpl==38 & highschoolentryyear>=2006
replace evolution_score=30 if bpl==39 & highschoolentryyear<2006
replace evolution_score=86 if bpl==39 & highschoolentryyear>=2006
replace evolution_score=25 if bpl==40 & highschoolentryyear<2005
replace evolution_score=25 if bpl==40 & highschoolentryyear>=2005
replace evolution_score=82 if bpl==41 & highschoolentryyear<2009
replace evolution_score=82 if bpl==41 & highschoolentryyear>=2009
replace evolution_score=91 if bpl==42 & highschoolentryyear<2002
replace evolution_score=96 if bpl==42 & highschoolentryyear>=2002
replace evolution_score=100 if bpl==44 & highschoolentryyear<2006
replace evolution_score=82 if bpl==44 & highschoolentryyear>=2006
replace evolution_score=95 if bpl==45 & highschoolentryyear<2005
replace evolution_score=91 if bpl==45 & highschoolentryyear>=2005
replace evolution_score=82 if bpl==46 & highschoolentryyear<2005
replace evolution_score=77 if bpl==46 & highschoolentryyear>=2005
replace evolution_score=2 if bpl==47 & highschoolentryyear<2007
replace evolution_score=55 if bpl==47 & highschoolentryyear>=2007
replace evolution_score=64 if bpl==48 & highschoolentryyear<2009
replace evolution_score=46 if bpl==48 & highschoolentryyear>=2009
replace evolution_score=82 if bpl==49 & highschoolentryyear<2003
replace evolution_score=82 if bpl==49 & highschoolentryyear>=2003
replace evolution_score=86 if bpl==50 & highschoolentryyear<2000
replace evolution_score=86 if bpl==50 & highschoolentryyear>=2000
replace evolution_score=50 if bpl==51 & highschoolentryyear<2003
replace evolution_score=68 if bpl==51 & highschoolentryyear>=2003
replace evolution_score=86 if bpl==53 & highschoolentryyear<2005
replace evolution_score=86 if bpl==53 & highschoolentryyear>=2005
replace evolution_score=2 if bpl==54 & highschoolentryyear<2008
replace evolution_score=46 if bpl==54 & highschoolentryyear>=2008
replace evolution_score=55 if bpl==55
replace evolution_score=36 if bpl==56 & highschoolentryyear<2003
replace evolution_score=61 if bpl==56 & highschoolentryyear>=2003
gen evo_score = evolution_score/100
label variable evo_score "Evolution Score"

gen evolution_score_dosage=.
replace evolution_score_dosage= 9 if bpl==1 & highschoolentryyear<2002
replace evolution_score_dosage= 12 if bpl==1 & highschoolentryyear==2002
replace evolution_score_dosage= 15 if bpl==1 & highschoolentryyear==2003
replace evolution_score_dosage= 18 if bpl==1 & highschoolentryyear==2004
replace evolution_score_dosage= 21 if bpl==1 & highschoolentryyear>=2005
replace evolution_score_dosage= 48 if bpl==2 & highschoolentryyear<2003
replace evolution_score_dosage= 50.75 if bpl==2 & highschoolentryyear==2003
replace evolution_score_dosage= 53.5 if bpl==2 & highschoolentryyear==2004
replace evolution_score_dosage= 56.25 if bpl==2 & highschoolentryyear==2005
replace evolution_score_dosage= 59 if bpl==2 & highschoolentryyear>=2006
replace evolution_score_dosage= 82 if bpl==4 & highschoolentryyear<2005
replace evolution_score_dosage= 82 if bpl==4 & highschoolentryyear>=2005
replace evolution_score_dosage= 55 if bpl==5 & highschoolentryyear<2002
replace evolution_score_dosage= 57.75 if bpl==5 & highschoolentryyear==2002
replace evolution_score_dosage= 60.5 if bpl==5 & highschoolentryyear==2003
replace evolution_score_dosage= 63.25 if bpl==5 & highschoolentryyear==2004
replace evolution_score_dosage= 66 if bpl==5 & highschoolentryyear>=2005
replace evolution_score_dosage= 100 if bpl==6
replace evolution_score_dosage= 86 if bpl==8 & highschoolentryyear<2006
replace evolution_score_dosage= 85 if bpl==8 & highschoolentryyear==2006
replace evolution_score_dosage= 84 if bpl==8 & highschoolentryyear==2007
replace evolution_score_dosage= 83 if bpl==8 & highschoolentryyear==2008
replace evolution_score_dosage= 82 if bpl==8 & highschoolentryyear>=2009
replace evolution_score_dosage= 100 if bpl==9 & highschoolentryyear<2001
replace evolution_score_dosage= 89.75 if bpl==9 & highschoolentryyear==2001
replace evolution_score_dosage= 79.5 if bpl==9 & highschoolentryyear==2002
replace evolution_score_dosage= 69.25 if bpl==9 & highschoolentryyear==2003
replace evolution_score_dosage= 59 if bpl==9 & highschoolentryyear>=2004
replace evolution_score_dosage= 91 if bpl==10 & highschoolentryyear<2003
replace evolution_score_dosage= 88.25 if bpl==10 & highschoolentryyear==2003
replace evolution_score_dosage= 85.5 if bpl==10 & highschoolentryyear==2004
replace evolution_score_dosage= 82.75 if bpl==10 & highschoolentryyear==2005
replace evolution_score_dosage= 80 if bpl==10 & highschoolentryyear>=2006
replace evolution_score_dosage= 80 if bpl==11 & highschoolentryyear<2003
replace evolution_score_dosage= 84 if bpl==11 & highschoolentryyear==2003
replace evolution_score_dosage= 88 if bpl==11 & highschoolentryyear==2004
replace evolution_score_dosage= 92 if bpl==11 & highschoolentryyear==2005
replace evolution_score_dosage= 96 if bpl==11 & highschoolentryyear>=2006
replace evolution_score_dosage= 16 if bpl==12 & highschoolentryyear<2005
replace evolution_score_dosage= 34.75 if bpl==12 & highschoolentryyear==2005
replace evolution_score_dosage= 53.5 if bpl==12 & highschoolentryyear==2006
replace evolution_score_dosage= 72.25 if bpl==12 & highschoolentryyear==2007
replace evolution_score_dosage= 91 if bpl==12 & highschoolentryyear>=2008
replace evolution_score_dosage= 7 if bpl==13 & highschoolentryyear<2001
replace evolution_score_dosage= 21.75 if bpl==13 & highschoolentryyear==2001
replace evolution_score_dosage= 36.5 if bpl==13 & highschoolentryyear==2002
replace evolution_score_dosage= 51.25 if bpl==13 & highschoolentryyear==2003
replace evolution_score_dosage= 66 if bpl==13 & highschoolentryyear>=2004
replace evolution_score_dosage= 91 if bpl==15 & highschoolentryyear<2002
replace evolution_score_dosage= 87 if bpl==15 & highschoolentryyear==2002
replace evolution_score_dosage= 83 if bpl==15 & highschoolentryyear==2003
replace evolution_score_dosage= 79 if bpl==15 & highschoolentryyear==2004
replace evolution_score_dosage= 75 if bpl==15 & highschoolentryyear>=2005
replace evolution_score_dosage= 82 if bpl==16 & highschoolentryyear<2007
replace evolution_score_dosage= 82 if bpl==16 & highschoolentryyear>=2007
replace evolution_score_dosage= 45 if bpl==17 & highschoolentryyear<2001
replace evolution_score_dosage= 54.25 if bpl==17 & highschoolentryyear==2001
replace evolution_score_dosage= 63.5 if bpl==17 & highschoolentryyear==2002
replace evolution_score_dosage= 72.25 if bpl==17 & highschoolentryyear==2003
replace evolution_score_dosage= 82 if bpl==17 & highschoolentryyear>=2004
replace evolution_score_dosage= 100 if bpl==18 & highschoolentryyear<2003
replace evolution_score_dosage= 99 if bpl==18 & highschoolentryyear==2003
replace evolution_score_dosage= 98 if bpl==18 & highschoolentryyear==2004
replace evolution_score_dosage= 97 if bpl==18 & highschoolentryyear==2005
replace evolution_score_dosage= 96 if bpl==18 & highschoolentryyear>=2006
replace evolution_score_dosage= 77 if bpl==19 & highschoolentryyear>=2007
replace evolution_score_dosage= 0 if bpl==20 & highschoolentryyear<2004
replace evolution_score_dosage= 24 if bpl==20 & highschoolentryyear==2004
replace evolution_score_dosage= 48 if bpl==20 & highschoolentryyear==2005
replace evolution_score_dosage= 72 if bpl==20 & highschoolentryyear==2006
replace evolution_score_dosage= 96 if bpl==20 & highschoolentryyear>=2007
replace evolution_score_dosage= 55 if bpl==21 & highschoolentryyear<2006
replace evolution_score_dosage= 55 if bpl==21 & highschoolentryyear>=2006
replace evolution_score_dosage= 64 if bpl==22 & highschoolentryyear<2002
replace evolution_score_dosage= 54.75 if bpl==22 & highschoolentryyear==2002
replace evolution_score_dosage= 45.5 if bpl==22 & highschoolentryyear==2003
replace evolution_score_dosage= 36.25 if bpl==22 & highschoolentryyear==2004
replace evolution_score_dosage= 27 if bpl==22 & highschoolentryyear>=2005
replace evolution_score_dosage= 30 if bpl==23 & highschoolentryyear<2004
replace evolution_score_dosage= 39.5 if bpl==23 & highschoolentryyear==2004
replace evolution_score_dosage= 49 if bpl==23 & highschoolentryyear==2005
replace evolution_score_dosage= 58.5 if bpl==23 & highschoolentryyear==2006
replace evolution_score_dosage= 68 if bpl==23 & highschoolentryyear>=2007
replace evolution_score_dosage= 77 if bpl==24 & highschoolentryyear<1999
replace evolution_score_dosage= 76 if bpl==24 & highschoolentryyear==1999
replace evolution_score_dosage= 75 if bpl==24 & highschoolentryyear==2000
replace evolution_score_dosage= 74 if bpl==24 & highschoolentryyear==2001
replace evolution_score_dosage= 73 if bpl==24 & highschoolentryyear>=2002
replace evolution_score_dosage= 82 if bpl==25 & highschoolentryyear<2003
replace evolution_score_dosage= 82.5 if bpl==25 & highschoolentryyear==2003
replace evolution_score_dosage= 83 if bpl==25 & highschoolentryyear==2004
replace evolution_score_dosage= 83.5 if bpl==25 & highschoolentryyear==2005
replace evolution_score_dosage= 84 if bpl==25 & highschoolentryyear>=2006
replace evolution_score_dosage= 84 if bpl==26 & highschoolentryyear<1997
replace evolution_score_dosage= 83 if bpl==26 & highschoolentryyear==1997
replace evolution_score_dosage= 82 if bpl==26 & highschoolentryyear==1998
replace evolution_score_dosage= 81 if bpl==26 & highschoolentryyear==1999
replace evolution_score_dosage= 80 if bpl==26 & highschoolentryyear>=2000
replace evolution_score_dosage= 86 if bpl==27 & highschoolentryyear<2006
replace evolution_score_dosage= 86.75 if bpl==27 & highschoolentryyear==2006
replace evolution_score_dosage= 87.5 if bpl==27 & highschoolentryyear==2007
replace evolution_score_dosage= 88.25 if bpl==27 & highschoolentryyear==2008
replace evolution_score_dosage= 89 if bpl==27 & highschoolentryyear>=2009
replace evolution_score_dosage= 5 if bpl==28 & highschoolentryyear<2005
replace evolution_score_dosage= 25.5 if bpl==28 & highschoolentryyear==2005
replace evolution_score_dosage= 45.5 if bpl==28 & highschoolentryyear==2006
replace evolution_score_dosage= 65.75 if bpl==28 & highschoolentryyear==2007
replace evolution_score_dosage= 86 if bpl==28 & highschoolentryyear>=2008
replace evolution_score_dosage= 82 if bpl==29 & highschoolentryyear<2005
replace evolution_score_dosage= 81 if bpl==29 & highschoolentryyear==2005
replace evolution_score_dosage= 80 if bpl==29 & highschoolentryyear==2006
replace evolution_score_dosage= 79 if bpl==29 & highschoolentryyear==2007
replace evolution_score_dosage= 78 if bpl==29 & highschoolentryyear>=2008
replace evolution_score_dosage= 82 if bpl==30 & highschoolentryyear<2003
replace evolution_score_dosage= 80.25 if bpl==30 & highschoolentryyear==2003
replace evolution_score_dosage= 78.5 if bpl==30 & highschoolentryyear==2004
replace evolution_score_dosage= 76.75 if bpl==30 & highschoolentryyear==2005
replace evolution_score_dosage= 75 if bpl==30 & highschoolentryyear>=2006
replace evolution_score_dosage= 66 if bpl==31 
replace evolution_score_dosage= 70 if bpl==32 & highschoolentryyear<2001
replace evolution_score_dosage= 71.75 if bpl==32 & highschoolentryyear==2001
replace evolution_score_dosage= 73.5 if bpl==32 & highschoolentryyear==2002
replace evolution_score_dosage= 75.25 if bpl==32 & highschoolentryyear==2003
replace evolution_score_dosage= 77 if bpl==32 & highschoolentryyear>=2004
replace evolution_score_dosage= 23 if bpl==33 & highschoolentryyear<2003
replace evolution_score_dosage= 40 if bpl==33 & highschoolentryyear==2003
replace evolution_score_dosage= 57 if bpl==33 & highschoolentryyear==2004
replace evolution_score_dosage= 74 if bpl==33 & highschoolentryyear==2005
replace evolution_score_dosage= 91 if bpl==33 & highschoolentryyear>=2006
replace evolution_score_dosage= 100 if bpl==34 & highschoolentryyear<2002
replace evolution_score_dosage= 100 if bpl==34 & highschoolentryyear>=2002
replace evolution_score_dosage= 73 if bpl==35 & highschoolentryyear<2000
replace evolution_score_dosage= 77.5 if bpl==35 & highschoolentryyear==2000
replace evolution_score_dosage= 82 if bpl==35 & highschoolentryyear==2001
replace evolution_score_dosage= 86.5 if bpl==35 & highschoolentryyear==2002
replace evolution_score_dosage= 91 if bpl==35 & highschoolentryyear>=2003
replace evolution_score_dosage= 68 if bpl==36 
replace evolution_score_dosage= 100 if bpl==37 & highschoolentryyear<2001
replace evolution_score_dosage= 95.5 if bpl==37 & highschoolentryyear==2001
replace evolution_score_dosage= 91 if bpl==37 & highschoolentryyear==2002
replace evolution_score_dosage= 86.5 if bpl==37 & highschoolentryyear==2003
replace evolution_score_dosage= 82 if bpl==37 & highschoolentryyear>=2004
replace evolution_score_dosage= 9 if bpl==38 & highschoolentryyear<2003
replace evolution_score_dosage= 22.75 if bpl==38 & highschoolentryyear==2003
replace evolution_score_dosage= 36.5 if bpl==38 & highschoolentryyear==2004
replace evolution_score_dosage= 50.25 if bpl==38 & highschoolentryyear==2005
replace evolution_score_dosage= 64 if bpl==38 & highschoolentryyear>=2006
replace evolution_score_dosage= 30 if bpl==39 & highschoolentryyear<2003
replace evolution_score_dosage= 44 if bpl==39 & highschoolentryyear==2003
replace evolution_score_dosage= 58 if bpl==39 & highschoolentryyear==2004
replace evolution_score_dosage= 72 if bpl==39 & highschoolentryyear==2005
replace evolution_score_dosage= 86 if bpl==39 & highschoolentryyear>=2006
replace evolution_score_dosage= 25 if bpl==40 & highschoolentryyear<2005
replace evolution_score_dosage= 25 if bpl==40 & highschoolentryyear>=2005
replace evolution_score_dosage= 82 if bpl==41 & highschoolentryyear<2009
replace evolution_score_dosage= 82 if bpl==41 & highschoolentryyear>=2009
replace evolution_score_dosage= 91 if bpl==42 & highschoolentryyear<2002
replace evolution_score_dosage= 92.25 if bpl==42 & highschoolentryyear==2002
replace evolution_score_dosage= 93.5 if bpl==42 & highschoolentryyear==2002
replace evolution_score_dosage= 94.75 if bpl==42 & highschoolentryyear==2002
replace evolution_score_dosage= 96 if bpl==42 & highschoolentryyear>=2002
replace evolution_score_dosage= 100 if bpl==44 & highschoolentryyear<2003
replace evolution_score_dosage= 95.5 if bpl==44 & highschoolentryyear==2003
replace evolution_score_dosage= 91 if bpl==44 & highschoolentryyear==2004
replace evolution_score_dosage= 86.5 if bpl==44 & highschoolentryyear==2005
replace evolution_score_dosage= 82 if bpl==44 & highschoolentryyear>=2006
replace evolution_score_dosage= 95 if bpl==45 & highschoolentryyear<2002
replace evolution_score_dosage= 94 if bpl==45 & highschoolentryyear==2002
replace evolution_score_dosage= 93 if bpl==45 & highschoolentryyear==2003
replace evolution_score_dosage= 92 if bpl==45 & highschoolentryyear==2004
replace evolution_score_dosage= 91 if bpl==45 & highschoolentryyear>=2005
replace evolution_score_dosage= 82 if bpl==46 & highschoolentryyear<2002
replace evolution_score_dosage= 80.75 if bpl==46 & highschoolentryyear==2002
replace evolution_score_dosage= 79.5 if bpl==46 & highschoolentryyear==2003
replace evolution_score_dosage= 78.25 if bpl==46 & highschoolentryyear==2004
replace evolution_score_dosage= 77 if bpl==46 & highschoolentryyear>=2005
replace evolution_score_dosage= 2 if bpl==47 & highschoolentryyear<2004
replace evolution_score_dosage= 15.25 if bpl==47 & highschoolentryyear==2004
replace evolution_score_dosage= 28.5 if bpl==47 & highschoolentryyear==2005
replace evolution_score_dosage= 41.75 if bpl==47 & highschoolentryyear==2006
replace evolution_score_dosage= 55 if bpl==47 & highschoolentryyear>=2007
replace evolution_score_dosage= 64 if bpl==48 & highschoolentryyear<2006
replace evolution_score_dosage= 59.5 if bpl==48 & highschoolentryyear==2006
replace evolution_score_dosage= 55 if bpl==48 & highschoolentryyear==2007
replace evolution_score_dosage= 50.5 if bpl==48 & highschoolentryyear==2008
replace evolution_score_dosage= 46 if bpl==48 & highschoolentryyear>=2009
replace evolution_score_dosage= 82 if bpl==49 & highschoolentryyear<2003
replace evolution_score_dosage= 82 if bpl==49 & highschoolentryyear>=2003
replace evolution_score_dosage= 86 if bpl==50 & highschoolentryyear<2000
replace evolution_score_dosage= 86 if bpl==50 & highschoolentryyear>=2000
replace evolution_score_dosage= 50 if bpl==51 & highschoolentryyear<2000
replace evolution_score_dosage= 54.5 if bpl==51 & highschoolentryyear==2000
replace evolution_score_dosage= 59 if bpl==51 & highschoolentryyear==2001
replace evolution_score_dosage= 63.5 if bpl==51 & highschoolentryyear==2002
replace evolution_score_dosage= 68 if bpl==51 & highschoolentryyear>=2003
replace evolution_score_dosage= 86 if bpl==53 & highschoolentryyear<2005
replace evolution_score_dosage= 86 if bpl==53 & highschoolentryyear>=2005
replace evolution_score_dosage= 2 if bpl==54 & highschoolentryyear<2005
replace evolution_score_dosage= 13 if bpl==54 & highschoolentryyear==2005
replace evolution_score_dosage= 24 if bpl==54 & highschoolentryyear==2006
replace evolution_score_dosage= 35 if bpl==54 & highschoolentryyear==2007
replace evolution_score_dosage= 46 if bpl==54 & highschoolentryyear>=2008
replace evolution_score_dosage= 2 if bpl==55 
replace evolution_score_dosage= 36 if bpl==56 & highschoolentryyear<2000
replace evolution_score_dosage= 42.25 if bpl==56 & highschoolentryyear==2000
replace evolution_score_dosage= 48.5 if bpl==56 & highschoolentryyear==2001
replace evolution_score_dosage= 54.75 if bpl==56 & highschoolentryyear==2002
replace evolution_score_dosage= 61 if bpl==56 & highschoolentryyear>=2003
gen evo_score_dosage=evolution_score_dosage/100
label variable evo_score_dosage "Evolution Score"

foreach i of num 1/9 { 
gen evo_score_`i'=0
replace evo_score_`i'=1 if evo_score>0.`i'
replace evo_score_`i'=. if evo_score==.
label variable evo_score_`i' "Evolution Score $>$ 0.`i'0"
}

gen more_evolution=0 
replace more_evolution=1 if bpl==1 | bpl==2 |  bpl==5 |  bpl==11 | bpl==12 |  bpl==13 |  bpl==17 |  bpl==20 |  bpl==23 |  bpl==25 |  bpl==27 |  bpl==28 |  bpl==32 |  bpl==33 |  bpl==35 |  bpl==38 |  bpl==39 |  bpl==42 |  bpl==47 |  bpl==51 |  bpl==54 |  bpl==56

gen less_evolution=0 
replace less_evolution=1 if bpl==8 |  bpl==9 |  bpl==10 |  bpl==15 | bpl==18 | bpl==22 |  bpl==24 |  bpl==26 |  bpl==29 |  bpl==30 | bpl==37 |  bpl==44 |  bpl==45 |  bpl==46 |  bpl==48

gen equal_evolution=0 
replace equal_evolution=1 if bpl==4 | bpl==6 |   bpl==16 |  bpl==19 |  bpl==21 |  bpl==31 |  bpl==34 |  bpl==36 |  bpl==40 |  bpl==41 |  bpl==49 |  bpl==50 |  bpl==53 |  bpl==55

gen first_treat =.
replace first_treat=2005 if bpl==1
replace first_treat=2006 if bpl==2
replace first_treat=2005 if bpl==4
replace first_treat=2005 if bpl==5
replace first_treat=2009 if bpl==8
replace first_treat=2004 if bpl==9
replace first_treat=2006 if bpl==10
replace first_treat=2006 if bpl==11
replace first_treat=2008 if bpl==12
replace first_treat=2004 if bpl==13
replace first_treat=2005 if bpl==15
replace first_treat=2007 if bpl==16
replace first_treat=2004 if bpl==17
replace first_treat=2006 if bpl==18
replace first_treat=2007 if bpl==20
replace first_treat=2006 if bpl==21
replace first_treat=2005 if bpl==22
replace first_treat=2007 if bpl==23
replace first_treat=2002 if bpl==24
replace first_treat=2006 if bpl==25
replace first_treat=2000 if bpl==26
replace first_treat=2009 if bpl==27
replace first_treat=2008 if bpl==28
replace first_treat=2008 if bpl==29
replace first_treat=2006 if bpl==30
replace first_treat=2004 if bpl==32
replace first_treat=2006 if bpl==33
replace first_treat=2002 if bpl==34
replace first_treat=2003 if bpl==35
replace first_treat=2004 if bpl==37
replace first_treat=2006 if bpl==38
replace first_treat=2006 if bpl==39
replace first_treat=2005 if bpl==40
replace first_treat=2009 if bpl==41
replace first_treat=2002 if bpl==42
replace first_treat=2006 if bpl==44
replace first_treat=2005 if bpl==45
replace first_treat=2005 if bpl==46
replace first_treat=2007 if bpl==47
replace first_treat=2009 if bpl==48
replace first_treat=2003 if bpl==49
replace first_treat=2000 if bpl==50
replace first_treat=2003 if bpl==51
replace first_treat=2005 if bpl==53
replace first_treat=2008 if bpl==54
replace first_treat=2003 if bpl==56
replace first_treat=0 if first_treat==.
gene id=_n

gen trend=0
replace trend= highschoolentryyear - 2005 if bpl==1
replace trend= highschoolentryyear - 2006 if bpl==2
replace trend= highschoolentryyear - 2005 if bpl==5
replace trend= highschoolentryyear - 2009 if bpl==8
replace trend= highschoolentryyear - 2004 if bpl==9
replace trend= highschoolentryyear - 2006 if bpl==10
replace trend= highschoolentryyear - 2006 if bpl==11
replace trend= highschoolentryyear - 2008 if bpl==12
replace trend= highschoolentryyear - 2004 if bpl==13
replace trend= highschoolentryyear - 2005 if bpl==15
replace trend= highschoolentryyear - 2004 if bpl==17
replace trend= highschoolentryyear - 2006 if bpl==18
replace trend= highschoolentryyear - 2007 if bpl==19
replace trend= highschoolentryyear - 2007 if bpl==20
replace trend= highschoolentryyear - 2005 if bpl==22
replace trend= highschoolentryyear - 2007 if bpl==23
replace trend= highschoolentryyear - 2002 if bpl==24
replace trend= highschoolentryyear - 2006 if bpl==25
replace trend= highschoolentryyear - 2000 if bpl==26
replace trend= highschoolentryyear - 2009 if bpl==27
replace trend= highschoolentryyear - 2008 if bpl==28
replace trend= highschoolentryyear - 2008 if bpl==29
replace trend= highschoolentryyear - 2006 if bpl==30
replace trend= highschoolentryyear - 2004 if bpl==32
replace trend= highschoolentryyear - 2006 if bpl==33
replace trend= highschoolentryyear - 2003 if bpl==35
replace trend= highschoolentryyear - 2004 if bpl==37
replace trend= highschoolentryyear - 2006 if bpl==38
replace trend= highschoolentryyear - 2006 if bpl==39
replace trend= highschoolentryyear - 2002 if bpl==42
replace trend= highschoolentryyear - 2006 if bpl==44
replace trend= highschoolentryyear - 2005 if bpl==45
replace trend= highschoolentryyear - 2005 if bpl==46
replace trend= highschoolentryyear - 2007 if bpl==47
replace trend= highschoolentryyear - 2009 if bpl==48
replace trend= highschoolentryyear - 2003 if bpl==51
replace trend= highschoolentryyear - 2008 if bpl==54
replace trend= highschoolentryyear - 2003 if bpl==56

gen birth_norm=birthyr-1977
tab bpl, generate(bpl_dum)

forval i = 1/51 {
gen statelineartrend`i'=birth_norm*bpl_dum`i'
gen sq_statelineartrend`i'=birth_norm*birth_norm*bpl_dum`i'
}

global statelineartrend "statelineartrend*"
global sq_statelineartrend "sq_statelineartrend*"

gen closestate10=0
replace closestate10=1 if bpl==4 | bpl==5 | bpl==10 | bpl==12 | bpl==13 | bpl==15 | bpl==16 | bpl==17 | bpl==18 | bpl==19 | bpl==23 | bpl==25 | bpl==29 | bpl==30 | bpl==33 | bpl==37 | bpl==40 | bpl==41 | bpl==44 | bpl==51 | bpl==56
replace closestate10=. if bpl==.

gen onereform=0
replace onereform=1 if bpl==5 | bpl==9 | bpl==10 | bpl==11 | bpl==12 | bpl==13 | bpl==15 | bpl==17 | bpl==23 | bpl==26 | bpl==30 | bpl==32 | bpl==33 | bpl==35 | bpl==37 | bpl==42 | bpl==44 | bpl==46 | bpl==48 | bpl==51 | bpl==56
replace onereform=. if bpl==.

gen largestate=0
replace largestate=1 if bpl==6 | bpl==48 | bpl==12 | bpl==36 | bpl==42 | bpl==17 | bpl==39 | bpl==13 | bpl==37 | bpl==26 | bpl==34 | bpl==51 | bpl==53 | bpl==4 | bpl==25 | bpl==47 | bpl==18 | bpl==24 | bpl==29 | bpl==55
replace largestate=. if bpl==.

gen textstate=0
replace textstate=1 if bpl==2 | bpl==5 | bpl==6 | bpl==8 | bpl==9 | bpl==10 | bpl==12| bpl==13| bpl==16| bpl==17| bpl==25| bpl==26| bpl==27| bpl==29| bpl==31| bpl==32| bpl==34| bpl==36| bpl==37 | bpl==39| bpl==41| bpl==44| bpl==46| bpl==49| bpl==50| bpl==51| bpl==55
replace textstate=. if bpl==.

***controls:
rename sex female
recode female (2=1) (1=0)
label define female 1 "female" 0 "male" 
label values female female
label variable female "Female"

gen white=race
recode white (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define white 1 "white" 0 "non-white" 
label values white white
label variable white "Race/Ethnicity: White"

gen black=race
recode black (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define black 1 "black" 0 "non-black" 
label values black black
label variable black "Race/Ethnicity: Black"

gen asian=race
recode asian (1=0) (2=0) (3=0) (4=1) (5=1) (6=1) (7=0) (8=0) (9=0)
label define asian 1 "asian" 0 "non-asian" 
label values asian asian
label variable asian "Race/Ethnicity: Asian"

gen native=race
recode native (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define native 1 "native" 0 "non-native" 
label values native native
label variable native "Race/Ethnicity: Native"

gen other=race
recode other (1=0) (2=0) (3=0) (4=0) (5=0) (6=0) (7=1) (8=0) (9=0)
label define other 1 "other" 0 "non-other" 
label values other other
label variable other "Race/Ethnicity: Other"

gen multiple=race
recode multiple (1=0) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=1) (9=1)
label define multiple 1 "multiple" 0 "non-multiple" 
label values multiple multiple
label variable multiple "Race/Ethnicity: Multiple"

rename hispan hispanic
recode hispanic (2=1) (3=1) (4=1)
label define hispanethnicity 1 "hispanic" 0 "non-hispanic" 
label values hispanic hispanethnicity 
label variable hispanic "Race/Ethnicity: Hispanic"

global controls "female black asian native other multiple hispanic i.year" 
global controls_indiv "female black asian native other multiple hispanic" 

drop if evo_score==. 
numlabel, add

***prepare event studies

gen zero=0

gen pre78=0
replace pre78=1 if trend==-7 | trend<=-8
replace pre78=. if trend==.

gen pre56=0
replace pre56=1 if trend==-5 | trend==-6
replace pre56=. if trend==.

gen pre34=0
replace pre34=1 if trend==-3 | trend==-4
replace pre34=. if trend==.

gen pre12=0
replace pre12=1 if trend==-1 | trend==-2
replace pre12=. if trend==.

gen post01=0
replace post01=1 if trend==0 | trend==1
replace post01=. if trend==.

gen post23=0
replace post23=1 if trend==2| trend==3
replace post23=. if trend==.

gen post45=0
replace post45=1 if trend==4| trend>=5
replace post45=. if trend==.

gen lifesciences_conv = lifesciences
replace lifesciences_conv = lifesciences_conv*(-1) if less_evolution==1

***merge other datasets

merge m:1 highschoolentryyear bpl  using "${path}\data\states\governors19912009.dta"
keep if highschoolentryyear>1990
keep if highschoolentryyear<2010
drop if highschoolentryyear==.
drop _merge

***prepare sample and save data

reg lifesciences evo_score $controls  i.bpl i.birthyr, cluster(bpl) baselevels
gen sample_acs=e(sample)

save "${path}\data\acs\acs_ready.dta", replace